//
//  CInfoView.m
//  HCHK_iphone
//
//  Created by yilong zhang on 12-1-1.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "CInfoView.h"

@implementation CInfoView

@synthesize delegate;
//@synthesize m_IconBg;
@synthesize m_Icon;
@synthesize m_IconBtn;

//imagepicker
@synthesize m_Sheet;
@synthesize m_PhotoCtrl;
@synthesize m_CamareCtrl;

@synthesize m_Nick;
@synthesize m_MyAttention;
@synthesize m_MyFriends;
@synthesize m_LogOutBtn;
@synthesize m_MyUpdGallery;
@synthesize m_NativeCnt;
@synthesize m_NetCnt;
@synthesize m_MyFodGallery;
@synthesize m_NativeMyfod;
@synthesize m_NetCntMyfod;
@synthesize m_FavortTask;
@synthesize m_UploadTask;
@synthesize m_Sel;

@synthesize m_MyTitle;
@synthesize m_FrdTitle;
@synthesize m_FrdNum;
@synthesize m_PrdTitle;
@synthesize m_PrdNum;
@synthesize m_ComTitle;
@synthesize m_ComNum;
@synthesize m_NoFavos;

@synthesize m_UserID;
@synthesize m_Favorites;
@synthesize m_Uploads;

@synthesize m_bIsMyFodLoading;
@synthesize m_bIsUpLoading;
@synthesize m_Indicator;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        // Initialization code
        //self.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
        UIImageView *bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        bg.image = [UIImage imageNamed:@"appbg.jpg"];
        [self addSubview:bg];
        [bg release];
        
        self.m_Title = @"我的资料";
        m_NoFavos.text = nil;
        
        m_bIsUpLoading   = NO;
        m_bIsMyFodLoading= NO;
       
        //my upload
        m_NativeCnt = [[CAscCounter alloc] init];
        m_NativeCnt.m_nOffset = 0;
        m_NativeCnt.m_nLimit  = 6;
        m_NetCnt = [[CAscCounter alloc] init];
        m_NetCnt.m_nOffset = 0;
        m_NetCnt.m_nLimit  = 6;
        
        //myfavorite
        m_NativeMyfod = [[CAscCounter alloc] init];
        m_NativeMyfod.m_nOffset = 0;
        m_NativeMyfod.m_nLimit  = 6;
        m_NetCntMyfod = [[CAscCounter alloc] init];
        m_NetCntMyfod.m_nOffset = 0;
        m_NetCntMyfod.m_nLimit  = 6;
        
        //m_IconBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 183)];
        //m_IconBg.image = [UIImage imageNamed:@"icon.png"];
        //[self addSubview:m_IconBg];
        //[m_IconBg release];
        
        UIView *shadow = [[UIView alloc] initWithFrame:CGRectMake(15, 10, 100, 100)];
        shadow.backgroundColor = [UIColor blackColor];
        shadow.layer.cornerRadius = 50;
        shadow.layer.shadowOffset = CGSizeMake(2, 2);
        shadow.layer.shadowOpacity= 0.8;
        shadow.layer.shadowColor  = [[UIColor blackColor] CGColor];
        [self addSubview:shadow];
        [shadow release];
        
        m_Icon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 100, 100)];
        m_Icon.layer.masksToBounds = YES;
        m_Icon.layer.cornerRadius  = 50;
        m_Icon.image = [UIImage imageNamed:@"dicon.png"];
        [self addSubview:m_Icon];
        [m_Icon release];
        
        m_IconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        m_IconBtn.frame = m_Icon.frame;
        m_IconBtn.alpha = 0.1;
        [m_IconBtn addTarget:self action:@selector(OnIconBtnDown:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:m_IconBtn];
        
        /*UIImageView *side = [[UIImageView alloc] initWithFrame:CGRectMake(20, 5, 150, 150)];
        side.image = [UIImage imageNamed:@"iconside.png"];
        [self addSubview:side];
        [side release];*/
        
        m_LogOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        m_LogOutBtn.frame = CGRectMake(self.frame.size.width-95, 73, 95, 41);
        [m_LogOutBtn setBackgroundImage:[UIImage imageNamed:@"logout.png"] forState:UIControlStateNormal];
        [m_LogOutBtn addTarget:self action:@selector(OnButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        m_LogOutBtn.tag = 2;
        [self addSubview:m_LogOutBtn];
        
        m_Nick = [[UILabel alloc] initWithFrame:CGRectMake(m_Icon.frame.origin.x+m_Icon.frame.size.width+5, 35, 190, 24)];
        m_Nick.backgroundColor = [UIColor clearColor];
        m_Nick.textColor = [UIColor colorWithRed:0.905 green:0.623 blue:0.294 alpha:1.0];
        m_Nick.text = @"昵称";
        m_Nick.font = [UIFont boldSystemFontOfSize:20];
        [self addSubview:m_Nick];
        [m_Nick release];
        
        /*m_MyAttention = [UIButton buttonWithType:UIButtonTypeCustom];
        m_MyAttention.frame = CGRectMake(35, 100, 70, 30);
        [m_MyAttention setTitle:@"我的关注" forState:UIControlStateNormal];
        [m_MyAttention setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        m_MyAttention.titleLabel.font = [UIFont systemFontOfSize:13];
        [m_MyAttention setBackgroundImage:[UIImage imageNamed:@"6.png"] forState:UIControlStateNormal];
        [m_MyAttention addTarget:self action:@selector(OnButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        m_MyAttention.tag = 0;
        [self addSubview:m_MyAttention];
        
        m_MyFriends = [UIButton buttonWithType:UIButtonTypeCustom];
        m_MyFriends.frame = CGRectMake(self.frame.size.width-30-70, 100, 70, 30);
        [m_MyFriends setTitle:@"我的好友" forState:UIControlStateNormal];
        [m_MyFriends setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        m_MyFriends.titleLabel.font = [UIFont systemFontOfSize:13];
        [m_MyFriends setBackgroundImage:[UIImage imageNamed:@"6.png"] forState:UIControlStateNormal];
        [m_MyFriends addTarget:self action:@selector(OnButtonDown:) forControlEvents:UIControlEventTouchUpInside];
        m_MyFriends.tag = 1;
        [self addSubview:m_MyFriends];*/
        
        m_Sel = [[UIImageView alloc] initWithFrame:CGRectMake(1, self.frame.size.height-270, 318, 270)];
        m_Sel.image = [UIImage imageNamed:@"infobg.png"];
        [self addSubview:m_Sel];
        [m_Sel release];
        
        //my favorites
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(18, m_Sel.frame.origin.y+5, 70, 18);
        btn.tag = 0;
        [btn setBackgroundImage:[UIImage imageNamed:@"myupload.png"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(OnTabSelected:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        
        //m_MyUpdGallery = [[CGalleryView alloc] initWithFrame:CGRectMake(5, btn.frame.origin.y+btn.frame.size.height+5, self.frame.size.width, GALLERY_HEIGHT) ItemSize:CGSizeMake(ICON_WIDTH, ICON_HEIGHT) Horizontal:YES];
        m_MyUpdGallery = [[CWaterFall alloc] initWithFrame:CGRectMake(2, 155, 312, self.frame.size.height-155) ColNum:3 WaterDropSize:CGSizeMake(312/3, 128)];
        m_MyUpdGallery.delegate = self;
        m_MyUpdGallery.alpha = 1.0;
        [self addSubview:m_MyUpdGallery];
        [m_MyUpdGallery release];
        
        //my upload
        btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(116, m_Sel.frame.origin.y+5, 70, 18);
        btn.tag = 1;
        [btn setBackgroundImage:[UIImage imageNamed:@"myfavorite.png"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(OnTabSelected:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        
        [self bringSubviewToFront:m_Sel];
        
        //m_MyFodGallery = [[CGalleryView alloc] initWithFrame:CGRectMake(5, btn.frame.origin.y+btn.frame.size.height+5, self.frame.size.width, GALLERY_HEIGHT) ItemSize:CGSizeMake(ICON_WIDTH, ICON_HEIGHT) Horizontal:YES];
        m_MyFodGallery = [[CWaterFall alloc] initWithFrame:CGRectMake(2, 155, 312, self.frame.size.height-155) ColNum:3 WaterDropSize:CGSizeMake(ICON_WIDTH, ICON_HEIGHT)];
        m_MyFodGallery.delegate = self;
        m_MyFodGallery.alpha = 0.0;
        [self addSubview:m_MyFodGallery];
        [m_MyFodGallery release];

        /*UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 125, frame.size.width, 1)];
        line.image = [UIImage imageNamed:@"line.png"];
        [self addSubview:line];
        [line release];
        
        m_FrdTitle = [[UILabel alloc] initWithFrame:CGRectMake(40, 130, 79, 25)];
        m_FrdTitle.text = @"我的好友";
        m_FrdTitle.backgroundColor = [UIColor clearColor];
        m_FrdTitle.textAlignment = UITextAlignmentCenter;
        m_FrdTitle.font = [UIFont systemFontOfSize:15];
        [self addSubview:m_FrdTitle];
        [m_FrdTitle release];
        
        m_FrdNum = [[UILabel alloc] initWithFrame:CGRectMake(40, 155, 79, 25)];
        m_FrdNum.text = @"(0)";
        m_FrdNum.backgroundColor = [UIColor clearColor];
        m_FrdNum.textAlignment = UITextAlignmentCenter;
        [self addSubview:m_FrdNum];
        [m_FrdNum release];
        
        line = [[UIImageView alloc] initWithFrame:CGRectMake(120, 130, 1, 50)];
        line.image = [UIImage imageNamed:@"vline.png"];
        [self addSubview:line];
        [line release];
        
        m_PrdTitle = [[UILabel alloc] initWithFrame:CGRectMake(121, 130, 78, 25)];
        m_PrdTitle.text = @"我的美食";
        m_PrdTitle.backgroundColor = [UIColor clearColor];
        m_PrdTitle.textAlignment = UITextAlignmentCenter;
        [self addSubview:m_PrdTitle];
        [m_PrdTitle release];
        
        m_PrdNum = [[UILabel alloc] initWithFrame:CGRectMake(121, 155, 78, 25)];
        m_PrdNum.text = @"(0)";
        m_PrdNum.backgroundColor = [UIColor clearColor];
        m_PrdNum.textAlignment = UITextAlignmentCenter;
        [self addSubview:m_PrdNum];
        [m_PrdNum release];
        
        line = [[UIImageView alloc] initWithFrame:CGRectMake(200, 130, 1, 50)];
        line.image = [UIImage imageNamed:@"vline.png"];
        [self addSubview:line];
        [line release];
        
        m_ComTitle = [[UILabel alloc] initWithFrame:CGRectMake(201, 130, 79, 25)];
        m_ComTitle.text = @"我的评价";
        m_ComTitle.backgroundColor = [UIColor clearColor];
        m_ComTitle.textAlignment = UITextAlignmentCenter;
        [self addSubview:m_ComTitle];
        [m_ComTitle release];
        
        m_ComNum = [[UILabel alloc] initWithFrame:CGRectMake(201, 155, 79, 25)];
        m_ComNum.text = @"(0)";
        m_ComNum.backgroundColor = [UIColor clearColor];
        m_ComNum.textAlignment = UITextAlignmentCenter;
        [self addSubview:m_ComNum];
        [m_ComNum release];
        
        line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 185, frame.size.width, 1)];
        line.image = [UIImage imageNamed:@"line.png"];
        [self addSubview:line];
        [line release];
  
        m_MyTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 205, frame.size.width, 25)];
        m_MyTitle.text = @"我的美食";
        m_MyTitle.backgroundColor = [UIColor clearColor];
        m_MyTitle.textAlignment = UITextAlignmentCenter;
        [self addSubview:m_MyTitle];
        [m_MyTitle release];
        
        line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 235, frame.size.width, 1)];
        line.image = [UIImage imageNamed:@"line.png"];
        [self addSubview:line];
        [line release];
        
        m_Gallary = [[CGalleryView alloc] initWithFrame:CGRectMake(0, 236, frame.size.width, 64) ItemSize:CGSizeMake(64, 64) Horizontal:YES];
        m_Gallary.m_delegate = self;
        [self addSubview:m_Gallary];
        [m_Gallary release];
        
        m_Indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(m_Gallary.frame.size.width-30, m_Gallary.frame.origin.y+19, 26, 26)];
        m_Indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
        m_Indicator.hidesWhenStopped = YES;
        [self addSubview:m_Indicator];
        [m_Indicator release];
        
        m_NoFavos = [[UILabel alloc] initWithFrame:CGRectMake(0, 236, frame.size.width, 64)];
        m_NoFavos.text = nil;//@"对不起，你还没有收藏。";
        m_NoFavos.textColor = [UIColor redColor];
        m_NoFavos.backgroundColor = [UIColor clearColor];
        m_NoFavos.textAlignment = UITextAlignmentCenter;
        m_NoFavos.font = m_FrdNum.font;
        [self addSubview:m_NoFavos];
        [m_NoFavos release];
        
        line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 300, frame.size.width, 1)];
        line.image = [UIImage imageNamed:@"line.png"];
        [self addSubview:line];
        [line release];*/
        
        m_Favorites = [[NSMutableArray alloc] init];
        m_Uploads   = [[NSMutableArray alloc] init];
    }
    
    return self;
}

-(void)dealloc
{
    [m_Favorites release];
    [m_Uploads release];
    
    [super dealloc];
}

-(void)OnTabSelected:(UIButton*)sender
{
    //upload
    if (0 == sender.tag)
    {
        m_Sel.image = [UIImage imageNamed:@"infobg.png"];
        
        m_MyUpdGallery.alpha = 1.0;
        m_MyFodGallery.alpha = 0.0;
        
        if (0 == [m_Uploads count])
            [self GetMyUpload];
    }
    //favorite
    else 
    {
        m_Sel.image = [UIImage imageNamed:@"infobgf.png"];
        
        m_MyUpdGallery.alpha = 0.0;
        m_MyFodGallery.alpha = 1.0;
        
        if (0 == [m_Favorites count])
            [self GetFavorites];
    }
}

//imagepicker
-(void)ShowPickerView
{
    if (!m_Sheet)
    {
        m_Sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"相册", @"拍照", nil];
        m_Sheet.actionSheetStyle = UIBarStyleBlackTranslucent;
        [m_Sheet showInView:[CRootCtrlManager DefaultRootCtrl].view];
    }
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //0-ALBUM
    //1-CAMERA
    //2-CANCEL
    [self DidPickerViewBtnDown:buttonIndex];
}

-(void)DidPickerViewBtnDown:(int)sender
{
    //photo
    if (0 == sender)
    {
        m_PhotoCtrl = [[PhotosViewController alloc] initWithSize:CGSizeMake(320, 320)];
        m_PhotoCtrl.m_delegate = self;
        m_PhotoCtrl.m_Target = self;
        m_PhotoCtrl.m_Action = @selector(DidPhotograph:);
        m_PhotoCtrl.m_PreView.m_TakeAgain.hidden = YES;
        [[CRootCtrlManager DefaultRootCtrl] presentModalViewController:m_PhotoCtrl animated:YES];
        [m_PhotoCtrl release];
    }
    //camare
    else if (1 == sender)
    {
        if ([CameraViewController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            m_CamareCtrl = [[CameraViewController alloc] initWithSize:CGSizeMake(320, 320)];
            m_CamareCtrl.m_delegate = self;
            m_CamareCtrl.m_Target = self;
            m_CamareCtrl.m_Action = @selector(DidPhotograph:);
            m_CamareCtrl.m_PreView.m_TakeAgain.hidden = YES;
            [[CRootCtrlManager DefaultRootCtrl] presentModalViewController:m_CamareCtrl animated:YES];
            [m_CamareCtrl release];
        }
        else 
        {
            UIAlertView *nocamera = [[UIAlertView alloc] initWithTitle:@"提示" message:@"抱歉，该设备不支持拍照功能。" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil];
            [nocamera show];
            [nocamera autorelease];
        }
    }
    //cancel
    else {;}
    
    [m_Sheet release];
    m_Sheet = nil;
}

-(void)DidPhotograph:(UIImage*)image
{
    /*if (image)
    {
        [[CRootCtrlManager DefaultRootCtrl] ShowLoadView:0.8 Title:@"头像修改中..."];
        NSData *data = UIImageJPEGRepresentation(image, 0.5);
        m_Icon.image = [UIImage imageWithData:data];
        [[CUser DefaultUser] SaveIcon:data];
        //m_IconBg.image= m_Icon.image;
        NSString *url = [NSString stringWithFormat:@"%@%d/%d/user", URL_UPLOADIMAGE, 150, 150];
        [[CDownLoadManager DefaultDownLoadManager]AddTask:url Sponsor:self PostData:data TimeOut:30 Data:[NSNumber numberWithLong:m_UserID] MType:PostImage UserInfo:[NSNumber numberWithShort:UploadIcon]];
    }*/
}

-(void)CImagePickerDidSelectImage:(UIImage *)image
{
    if (image)
    {
        [[CRootCtrlManager DefaultRootCtrl] ShowLoadView:0.8 Title:@"头像修改中..."];
        NSData *data = UIImageJPEGRepresentation(image, 0.5);
        m_Icon.image = [UIImage imageWithData:data];
        [[CUser DefaultUser] SaveIcon:data];
        //m_IconBg.image= m_Icon.image;
        NSString *url = [NSString stringWithFormat:@"%@%d/%d/user", URL_UPLOADIMAGE, 150, 150];
        [[CDownLoadManager DefaultDownLoadManager]AddTask:url Sponsor:self PostData:data TimeOut:30 Data:[NSNumber numberWithLong:m_UserID] MType:PostImage UserInfo:[NSNumber numberWithShort:UploadIcon]];
    }
}

-(void)ImagePickerDidSelectImage:(UIImage *)image
{
    if (image)
    {
        [[CRootCtrlManager DefaultRootCtrl] ShowLoadView:0.8 Title:@"头像修改中..."];
        NSData *data = UIImageJPEGRepresentation(image, 0.5);
        m_Icon.image = [UIImage imageWithData:data];
        [[CUser DefaultUser] SaveIcon:data];
        //m_IconBg.image= m_Icon.image;
        NSString *url = [NSString stringWithFormat:@"%@%d/%d/user", URL_UPLOADIMAGE, 150, 150];
        [[CDownLoadManager DefaultDownLoadManager]AddTask:url Sponsor:self PostData:data TimeOut:30 Data:[NSNumber numberWithLong:m_UserID] MType:PostImage UserInfo:[NSNumber numberWithShort:UploadIcon]];
    }
}

-(void)CommitAlterIcon:(NSString*)imgurl
{
    NSMutableString *request = [NSMutableString string];
    [request appendFormat:@"mobikey=%@", [CUser DefaultUser].U_Token];
    [request appendFormat:@"&sessionid=%@", [CUser DefaultUser].U_Session];
    [request appendFormat:@"&fid=%ld", [[CUser DefaultUser].U_AID longValue]];
    [request appendFormat:@"&action=%@", @"edit"];
    [request appendFormat:@"&userImg=%@", imgurl];
    
    //NSLog(@"\r\n\r\n修改头像:%@\r\n\r\n", request);
    
    [[CDownLoadManager DefaultDownLoadManager]AddTask:URL_ADDFRIEND Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithLong:m_UserID] MType:Post UserInfo:[NSNumber numberWithShort:AlterIcon]];
}

-(void)OnIconBtnDown:(UIButton *)sender
{
    [self ShowPickerView];
}

-(void)OnButtonDown:(UIButton*)sender
{
    [delegate DidClickButtonIndexInfoView:sender Object:self];
}

-(void)SetInfoViewInfo
{
    CUser *user = [CUser DefaultUser];
    
    if (m_UserID != [user.U_AID longValue])
    {
        //NSLog(@"\r\n用户头像url:%@\r\n", user.U_UrlIcon);
        
        user.m_IconView = m_Icon;
        m_Nick.text     = [NSString stringWithFormat:@"%@", user.U_Nick];
        
        m_UserID = [user.U_AID longValue];
        
        //获得个人头像
        user.m_IconView = m_Icon;
        NSData *data = [user GetUserIcon];
        //NSLog(@"\r\n\r\n头像url:%@", user.U_UrlIcon);
        if (data)
        {
            m_Icon.image = [UIImage imageWithData:data];
            //m_IconBg.image = m_Icon.image;
        }
        else 
        {
            m_Icon.image = [UIImage imageNamed:@"dicon.png"];
            user.m_IconView = m_Icon;
        }
        
        //get data from native
        //[m_MyFodGallery ShowIndicator];
        //[self GetFavorites];
        //[m_MyUpdGallery ShowIndicator];
        [self GetMyUpload];
    }
    else 
    {
        //获得个人头像
        NSData *data = [user GetUserIcon];
        //NSLog(@"\r\n\r\n头像url:%@", user.U_UrlIcon);
        if (data)
        {
            m_Icon.image = [UIImage imageWithData:data];
            //m_IconBg.image = m_Icon.image;
        }
        else 
        {
            m_Icon.image = [UIImage imageNamed:@"dicon.png"];
            user.m_IconView = m_Icon;
        }
        
        //get data from native
        //[m_MyFodGallery ShowIndicator];
        //[self GetFavorites];
        //[m_MyUpdGallery ShowIndicator];
        [self GetMyUpload];
    }
}

-(void)AddProductsToGalleryWithDic:(NSArray*)rets
{
    NSMutableArray *products = [NSMutableArray array];
    CProduct       *product  = nil;
    
    for (NSDictionary *dic in rets)
    {
        product = [[CProduct alloc] init];
        [product SetProductWithDic:dic Path:[AppConfig DefaultAppConfig].m_DelImagesPath];
        [products addObject:product];
        [product release];
    }
    
    [self AddProductsToGallery:products Type:4];
}

-(void)AddProductsToGallery:(NSArray*)rets Type:(int)type
{
    //CGalleyItem *item = nil;
    CWaterDrop *drop  = nil;
    CProduct   *food1 = nil;
    NSData     *data  = nil;
    UIImage    *image = nil;
    BOOL       bFIsInit= (0 == [m_Favorites count]) ? (YES) : (YES);
    BOOL       bUIsInit= (0 == [m_Uploads count]) ? (YES) : (YES);
    //NSMutableArray *arr = [NSMutableArray arrayWithCapacity:[rets count]];
    if ([rets count] > 0)
    {
        for (int i=0; i<[rets count]; i++)
        {
            food1 = (CProduct*)[rets objectAtIndex:i];
            
            if ( 0 == type)
            {
                if (bUIsInit)
                {
                    data  = [food1 GetProductIcon];
                    if (!data) 
                    {
                        [food1 DownLoadIcon];
                    }
                    else 
                    {
                        image = [UIImage imageWithData:data];
                    }
    
                    drop = [m_MyUpdGallery AddWaterDrop:image];
                    food1.m_IconView = drop.m_Image;
                    [m_Uploads addObject:food1];
                }
            }
            else if (1 == type)
            {
                if (bFIsInit)
                {
                    data = [food1 GetProductIcon];
                    if (!data) 
                    {
                        [food1 DownLoadIcon];
                    }
                    else 
                    {
                        image = [UIImage imageWithData:data];
                    }
                    
                    drop = [m_MyFodGallery AddWaterDrop:image];
                    food1.m_IconView = drop.m_Image;
                    [m_Favorites addObject:food1];
                }
            }
            else {;}
            
            /*item = [[CGalleyItem alloc] initWithImage:image];
            food1.m_IconView = item.m_ImageView;
            [arr addObject:item];
            [item release];
            if (0 == type)
                [m_Favorites addObject:food1];
            else if (1 == type)
                [m_Uploads addObject:food1];
            else 
                ;
            image = nil;*/
        }
        
        /*
        if ([arr count] > 0)
        {
            if (0 == type)
            {
                //m_MyFodGallery.m_ItemsData = m_Favorites;
                //[m_MyFodGallery SetItems:arr Item:nil];
                
                for (int i=0; i<[arr count]; i++)
                {
                    [m_MyFodGallery AddWaterDrop:nil];
                }
            }
            else if (1 == type)
            {
                //m_MyUpdGallery.m_ItemsData = m_Uploads;
                //[m_MyUpdGallery SetItems:arr Item:nil];
                
                for (int i=0; i<[arr count]; i++)
                {
                    
                }
            }
            else 
            {
                ;
            }
        }*/
    }
}

-(void)GetFavorites
{
    m_bIsMyFodLoading = YES;
    
    //网络不可用
    if (![AppConfig DefaultAppConfig].m_bIsNetWork)
    {
        m_NativeMyfod.m_nOffset = [m_Favorites count];
        NSArray *results = [self GetNativeFavorites];
        //本地没有数据或者已经读完
        if (results)
        {
            [self AddProductsToGallery:results Type:1];
        }
        else 
        {
            m_NativeMyfod.m_nLimit = 0;
        }
        
        //[m_MyFodGallery HiddenIndicator];
    }
    else 
    {
        m_NetCntMyfod.m_nOffset = [m_Favorites count];
        [self CommitGetFavoriteRequest];
    }
}

-(void)GetMyUpload
{
    m_bIsUpLoading = YES;
    
    //网络不可用
    if (![AppConfig DefaultAppConfig].m_bIsNetWork)
    {
        m_NativeCnt.m_nOffset = [m_Uploads count];
        NSArray *results = [self GetNativeUpload];
        //本地没有数据或者已经读完
        if (results)
        {
            [self AddProductsToGallery:results Type:0];
        }
        else 
        {
            m_NativeCnt.m_nLimit = 0;
            
        }
        //[m_MyUpdGallery HiddenIndicator];
    }
    else 
    {
        m_NetCnt.m_nOffset = [m_Uploads count];
        [self CommitGetMyUploadRequest];
    }
}

-(NSArray*)GetNativeFavorites
{
    NSArray *rets = nil;
    
    if (m_NativeCnt.m_nLimit > 0)
    {
        rets = [CProduct GetLimitProducts:[NSString stringWithFormat:@"%@_favorite", [CUser DefaultUser].U_Name] Where:nil Offset:m_NativeMyfod.m_nOffset Limit:m_NativeMyfod.m_nLimit];
    }
    
    return rets;
}

-(void)CommitGetFavoriteRequest
{
    if (Logined == [CUser DefaultUser].m_UType)
    {
        NSMutableString *request = [NSMutableString string];
        
        [request appendFormat:@"cursor=%d", m_NetCntMyfod.m_nOffset];
        [request appendFormat:@"&offset=%d", m_NetCntMyfod.m_nLimit];
        [request appendFormat:@"&action=%@", OP_GETFAVORITE_PRODUCT];
        [request appendFormat:@"&clientID=%@", [AppConfig DefaultAppConfig].m_strUDID];
        [request appendFormat:@"&mobikey=%@", [CUser DefaultUser].U_Token];
        [request appendFormat:@"&sessionid=%@", [CUser DefaultUser].U_Session];

        //NSLog(@"\r\n\r\n获得个人收藏请求:%@\r\n\r\n", request);
        
        self.m_FavortTask = [[CDownLoadManager DefaultDownLoadManager] AddTask:URL_GETPRODUTS Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithLong:m_UserID] MType:Post UserInfo:[NSNumber numberWithInt:1]];
    }
}

//-(void)DidReceiveMyFavoritesFromSvr:(NSArray*)results Type:(int)type
-(void)DidReceiveMyFavoritesFromSvr:(NSArray*)results
{
    CProduct *product = nil;
    NSMutableArray *arr= nil;
    NSArray *items = [results objectAtIndex:0];
    if ([items isKindOfClass:[NSArray class]])
    {
        if ([items count] > 0)
        {
            //清空本地缓冲
            if (0 == [m_Favorites count])
            {
                [[CDBManager ScheduledShareInstance] ClearTable:[NSString stringWithFormat:@"%@_favorite", [CUser DefaultUser].U_Name]];
                
                NSString *rootpath = [NSString stringWithFormat:@"Documents/%@", [CUser DefaultUser].U_Name];
                NSString *subpath  = [NSString stringWithFormat:@"%@", @"favorite"];
                [[AppConfig DefaultAppConfig] RemovePathInApp:rootpath SubPath:subpath];
                [[AppConfig DefaultAppConfig] CreatePathInApp:rootpath SubPath:subpath];
            }
            //加载新数据
            arr = [NSMutableArray array];
            for (NSDictionary *sub in items)
            {
                product = [[CProduct alloc] init];
                [product SetProductWithDic:sub Path:[CUser DefaultUser].m_FavoritePath];
                product.P_PubIconUrl = [CUser DefaultUser].U_UrlIcon;
                [product SaveProduct:[CUser DefaultUser].m_FavoriteTable];
                [arr addObject:product];
                [product release];
            }
        }
    }
    
    [self AddProductsToGallery:arr Type:[[results objectAtIndex:1] intValue]];
}

-(NSArray*)GetNativeUpload
{
    NSArray *rets = nil;
    
    if (m_NativeCnt.m_nLimit > 0)
    {
        rets = [CProduct GetLimitProducts:[NSString stringWithFormat:@"%@_upload", [CUser DefaultUser].U_Name] Where:nil Offset:m_NativeCnt.m_nOffset Limit:m_NativeCnt.m_nLimit];
    }
    
    return rets;
}

-(void)CommitGetMyUploadRequest
{
    if (Logined == [CUser DefaultUser].m_UType)
    {
        NSMutableString *request = [NSMutableString string];

        [request appendFormat:@"cursor=%d", m_NetCnt.m_nOffset];
        [request appendFormat:@"&offset=%d", m_NetCnt.m_nLimit];
        [request appendFormat:@"&action=%@", OP_GETUPLOAD_PRODUCT];
        [request appendFormat:@"&clientID=%@", [AppConfig DefaultAppConfig].m_strUDID];
        [request appendFormat:@"&mobikey=%@", [CUser DefaultUser].U_Token];
        [request appendFormat:@"&sessionid=%@", [CUser DefaultUser].U_Session];

        //NSLog(@"\r\n\r\n获得个人上传请求:%@\r\n\r\n", request);

        self.m_UploadTask = [[CDownLoadManager DefaultDownLoadManager] AddTask:URL_GETUSER_INFO Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithLong:m_UserID] MType:Post UserInfo:[NSNumber numberWithInt:0]];
    }
}

-(void)UpdateUserPdtNum:(NSDictionary*)results
{
    if ([[CUser DefaultUser].U_PdtNum intValue] != [[results objectForKey:@"CountArticle"] intValue])
    {
        int pdtnum = [[results objectForKey:@"CountArticle"] intValue];
        [CUser DefaultUser].U_PdtNum = [NSNumber numberWithInt:pdtnum];
        self.m_PrdNum.text = [NSString stringWithFormat:@"(%d)", pdtnum];
        
        pdtnum = [[results objectForKey:@"CountFriend"] intValue];
        [CUser DefaultUser].U_FrdNum = [NSNumber numberWithInt:pdtnum];
        self.m_FrdNum.text = [NSString stringWithFormat:@"(%d)", pdtnum];
        
        pdtnum = [[results objectForKey:@"CountComment"] intValue];
        [CUser DefaultUser].U_DisNum = [NSNumber numberWithInt:pdtnum];
        self.m_ComNum.text = [NSString stringWithFormat:@"(%d)", pdtnum];
        
        //更新
        NSMutableArray *keys = [NSMutableArray array];
        CKey *key = [[CKey alloc] initWithType:1 Value:[CUser DefaultUser].U_PdtNum Name:@"U_PdtNum"];
        [keys addObject:key];
        [key release];
        
        key = [[CKey alloc] initWithType:1 Value:[CUser DefaultUser].U_FrdNum Name:@"U_FrdNum"];
        [keys addObject:key];
        [key release];
        
        key = [[CKey alloc] initWithType:1 Value:[CUser DefaultUser].U_DisNum Name:@"U_DisNum"];
        [keys addObject:key];
        [key release];
        
        pdtnum = [CUser UpadteUserInfo:[NSString stringWithFormat:@"U_AID=%ld", [[CUser DefaultUser].U_AID longValue]] Keys:keys];
        if (pdtnum)
        {
            //NSLog(@"\r\n\r\n获得个人信息，更新用户美食数量失败\r\n\r\n");
        }
    }
}

-(void)ClearData
{
    m_UserID = 0;
    [CUser DefaultUser].m_IconView = nil;
    m_Icon.image = nil;
    //m_IconBg.image = nil;
    
    [m_Uploads removeAllObjects];
    //[m_MyUpdGallery ResetGallery];
    [m_MyUpdGallery InitWaterFall];
    m_bIsUpLoading        = NO;
    m_NetCnt.m_nLimit     = 6;
    m_NetCnt.m_nOffset    = 0;
    m_NativeCnt.m_nOffset = 0;
    m_NativeCnt.m_nLimit  = 6;
    
    [m_Favorites removeAllObjects];
    //[m_MyFodGallery ResetGallery];
    [m_MyFodGallery InitWaterFall];
    m_bIsMyFodLoading       = NO;
    m_NetCntMyfod.m_nLimit  = 6;
    m_NetCntMyfod.m_nOffset = 0;
    m_NativeMyfod.m_nOffset = 0;
    m_NativeMyfod.m_nLimit  = 6;
    
    [[CDownLoadManager DefaultDownLoadManager] CancelTask:self.m_FavortTask];
    [[CDownLoadManager DefaultDownLoadManager] CancelTask:self.m_UploadTask];
    self.m_UploadTask = nil;
    self.m_UploadTask = nil;
}

//-(void)DidReceiveMyUploadDataFromSvr:(NSDictionary*)results Type:(int)type
-(void)DidReceiveMyUploadDataFromSvr:(NSArray*)results;
{    
     CProduct *product = nil;
     NSMutableArray *arr= nil;
     NSArray *items = [[results objectAtIndex:0] objectForKey:@"Article"];
     if ([items isKindOfClass:[NSArray class]])
     {
         if ([items count] > 0)
         {
             //清空本地缓存
             if (0 == [m_Uploads count])
             {
                 [[CDBManager ScheduledShareInstance] ClearTable:[NSString stringWithFormat:@"%@_upload", [CUser DefaultUser].U_Name]];
                 
                 NSString *rootpath = [NSString stringWithFormat:@"Documents/%@", [CUser DefaultUser].U_Name];
                 NSString *subpath  = [NSString stringWithFormat:@"%@", @"upload"];
                 [[AppConfig DefaultAppConfig] RemovePathInApp:rootpath SubPath:subpath];
                 [[AppConfig DefaultAppConfig] CreatePathInApp:rootpath SubPath:subpath];
             }
             //加载新数据
             arr = [NSMutableArray array];
             for (NSDictionary *sub in items)
             {
                 product = [[CProduct alloc] init];
                 [product SetProductWithDic:sub Path:[CUser DefaultUser].m_UploadPath];
                 product.P_PubIconUrl = [CUser DefaultUser].U_UrlIcon;
                 [product SaveProduct:[CUser DefaultUser].m_UploadTable];
                 //[product SaveProduct:[CUser DefaultUser].m_UploadTable];
                 [arr addObject:product];
                 [product release];
             }
         }
     }
    
    [self AddProductsToGallery:arr Type:[[results objectAtIndex:1] intValue]];
}

//operation delegate
-(void)DidOperationFinished:(COperation *)op Data:(NSData *)data Other:(id)other UserInfo:(id)userinfo
{
    if (m_UserID == [other longValue])
    {
        NSString     *json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSDictionary *dic  = [json JSONValue];
        
        if (dic)
        {
            //NSLog(@"\r\nUploadPageCtrl:%@\r\n", [dic objectForKey:@"Msg"]);
            if (0 == [[dic objectForKey:@"Msg_error"] intValue])
            {
                //favorite
                if (1 == [userinfo intValue])
                {
                    //[self DidReceiveMyFavoritesFromSvr:[dic objectForKey:@"Resource"] Type:0];
                    [self performSelectorOnMainThread:@selector(DidReceiveMyFavoritesFromSvr:) withObject:[NSArray arrayWithObjects:[dic objectForKey:@"Resource"], [NSNumber numberWithInt:1], nil] waitUntilDone:YES];
                    m_bIsMyFodLoading = NO;
                    self.m_FavortTask = nil;
                    //[m_MyFodGallery HiddenIndicator];
                }
                //upload
                else if (0 == [userinfo intValue])
                {
                    //[self DidReceiveMyUploadDataFromSvr:[dic objectForKey:@"Resource"] Type:1];
                    [self performSelectorOnMainThread:@selector(DidReceiveMyUploadDataFromSvr:) withObject:[NSArray arrayWithObjects:[dic objectForKey:@"Resource"], [NSNumber numberWithInt:0], nil] waitUntilDone:YES];
                    m_bIsUpLoading    = NO;
                    self.m_UploadTask = nil;
                    //[m_MyUpdGallery HiddenIndicator];
                }
                //uploadicon
                else if (UploadIcon == [userinfo intValue])
                {
                    NSString *url = [dic objectForKey:@"big"];
                    if (url)
                    {
                        NSLog(@"\r\n\r\n头像修改成功\r\n\r\n旧的头像url:%@\r\n\r\n新的头像url:%@\r\n\r\n", [CUser DefaultUser].U_UrlIcon, url);
                        [CUser DefaultUser].U_UrlIcon = url;
                        NSNumber *number = (NSNumber*)other;
                        CKey *key = [[CKey alloc] initWithType:3 Value:url Name:@"U_UrlIcon"];
                        [CUser UpadteUserInfo:[NSString stringWithFormat:@"U_AID=%ld", [number longValue]] Keys:[NSArray arrayWithObjects:key, nil]];
                        [key release];
                        
                        [self CommitAlterIcon:url];
                        
                        [json release];
                        return;
                    }
                }
                else if (AlterIcon == [userinfo intValue])
                {
                    //
                }
            }
            else 
            {
                //favorite
                if (0 == [userinfo intValue])
                {
                    m_bIsMyFodLoading = NO;
                    self.m_FavortTask = nil;
                    //[m_MyFodGallery HiddenIndicator];
                }
                //upload
                else if (1 == [userinfo intValue])
                {
                    m_bIsUpLoading    = NO;
                    self.m_UploadTask = nil;
                    //[m_MyUpdGallery HiddenIndicator];
                }
            }
        }
        else 
        {
            //favorite
            if (0 == [userinfo intValue])
            {
                m_bIsMyFodLoading = NO;
                self.m_FavortTask = nil;
                //[m_MyFodGallery HiddenIndicator];
            }
            //upload
            else if (1 == [userinfo intValue])
            {
                m_bIsUpLoading    = NO;
                self.m_UploadTask = nil;
                //[m_MyUpdGallery HiddenIndicator];
            }
            //json error alterview            
            //NSLog(@"\r\n\r\n获取个人信息_Error:%@\r\n\r\n", json);
        }
        
        [json release];
    }
    else 
    {
        //favorite
        if (0 == [userinfo intValue])
        {
            m_bIsMyFodLoading = NO;
            self.m_FavortTask = nil;
            //[m_MyFodGallery HiddenIndicator];
        }
        //upload
        else if (1 == [userinfo intValue])
        {
            m_bIsUpLoading    = NO;
            self.m_UploadTask = NO;
            //[m_MyUpdGallery HiddenIndicator];
        }
    }

    [[CRootCtrlManager DefaultRootCtrl] HiddenLoadView];
}

-(void)DidOperationError:(COperation *)op Error:(NSError *)error Other:(id)other UserInfo:(id)userinfo
{
    //favorite
    if (0 == [userinfo intValue])
    {
        m_bIsMyFodLoading = NO;
        self.m_FavortTask = nil;
        //[m_MyFodGallery HiddenIndicator];
    }
    //upload
    else if (1 == [userinfo intValue])
    {
        m_bIsUpLoading    = NO;
        self.m_UploadTask = nil;
        //[m_MyUpdGallery HiddenIndicator];
    }

    [[CRootCtrlManager DefaultRootCtrl] HiddenLoadView];
}

-(void)DidOperationTimeOut:(COperation *)op Other:(id)other UserInfo:(id)userinfo
{
    //favorite
    if (0 == [userinfo intValue])
    {
        m_bIsMyFodLoading = NO;
        self.m_FavortTask = nil;
        //[m_MyFodGallery HiddenIndicator];
    }
    //upload
    else if (1 == [userinfo intValue])
    {
        m_bIsUpLoading    = NO;
        self.m_UploadTask = nil;
        //[m_MyUpdGallery HiddenIndicator];
    }

    [[CRootCtrlManager DefaultRootCtrl] HiddenLoadView];
}

-(void)DidDownLoadImage:(id)product Image:(NSData*)image
{
    //
}

-(void)DidDownLoadCommentaries:(id)product Commetaries:(NSArray*)coms
{
    //
}

-(void)DidDownLoadSuccess:(id)product OpType:(int)optype index:(int)index Info:(NSString*)info
{
    //
}

-(void)DidDownLoadError:(id)product OpType:(int)optype
{
    //
}

//waterfall
- (void)DidWaterFallButtom:(id)object
{
    if (m_MyFodGallery == object)
    {
        if (!m_bIsMyFodLoading)
        {
            [self GetFavorites];
        }
    }
    else if (m_MyUpdGallery == object)
    {
        if (!m_bIsUpLoading)
        {
            [self GetMyUpload];
        }
    }
    else {;}
}

- (void)WaterFallSelected:(id)object Index:(int)index
{
    //favorite
    if (m_MyFodGallery == object)
    {
        [[CRootCtrlManager DefaultRootCtrl].m_ComEdit SetComEditViewInfoEx:[m_Favorites objectAtIndex:index]];
        [[CRootCtrlManager DefaultRootCtrl].m_ComEdit GetDistance:[m_Favorites objectAtIndex:index] Coordinate:[CLocator DefaultLocator].m_Coordinate2D];
        [[CRootCtrlManager DefaultRootCtrl] ShowComEditView];
    } 
    //upload
    else if (m_MyUpdGallery == object)
    {
        [[CRootCtrlManager DefaultRootCtrl].m_ComEdit SetComEditViewInfoEx:[m_Uploads objectAtIndex:index]];
        [[CRootCtrlManager DefaultRootCtrl].m_ComEdit GetDistance:[m_Uploads objectAtIndex:index] Coordinate:[CLocator DefaultLocator].m_Coordinate2D];
        [[CRootCtrlManager DefaultRootCtrl] ShowComEditView];
    }
    else {;}
}

//gallery
-(void)DidGallerySelected:(int)index Directory:(int)directory Object:(id)object
{
    //favorite
    if (m_MyFodGallery == object)
    {
        [[CRootCtrlManager DefaultRootCtrl].m_ComEdit SetComEditViewInfoEx:[m_Favorites objectAtIndex:index]];
        [[CRootCtrlManager DefaultRootCtrl].m_ComEdit GetDistance:[m_Favorites objectAtIndex:index] Coordinate:[CLocator DefaultLocator].m_Coordinate2D];
        [[CRootCtrlManager DefaultRootCtrl] ShowComEditView];
    } 
    //upload
    else if (m_MyUpdGallery == object)
    {
        [[CRootCtrlManager DefaultRootCtrl].m_ComEdit SetComEditViewInfoEx:[m_Uploads objectAtIndex:index]];
        [[CRootCtrlManager DefaultRootCtrl].m_ComEdit GetDistance:[m_Uploads objectAtIndex:index] Coordinate:[CLocator DefaultLocator].m_Coordinate2D];
        [[CRootCtrlManager DefaultRootCtrl] ShowComEditView];
    }
    else {;}
}

-(void)DidGalleryDragEnd:(id)object
{
    if (m_MyFodGallery == object)
    {
        //[m_MyFodGallery ShowIndicator];
    }
    else if (m_MyUpdGallery == object)
    {
        //[m_MyUpdGallery ShowIndicator];
    }
    else {;}
}

-(void)DidGalleryBottom:(id)object
{
    if (m_MyFodGallery == object)
    {
        if (!m_bIsMyFodLoading)
        {
            [self GetFavorites];
        }
    }
    else if (m_MyUpdGallery == object)
    {
        if (!m_bIsUpLoading)
        {
            [self GetMyUpload];
        }
    }
    else {;}
}

-(void)DidGalleryTurnPage:(int)index Directory:(int)directory Object:(id)object
{
    CProduct *product = nil;
    CGalleyItem *item = nil;
    NSData *data = nil;
    UIImage*image= nil;
    int start = 0;
    int cnt   = 0;
    
    NSArray *subs = nil;
    int total = 0.0;
    if (m_MyFodGallery == object)
    {
        subs  = [m_MyFodGallery.m_RootPanel subviews];
        total = [[m_MyFodGallery.m_RootPanel subviews] count] - 1;
    }
    else if (m_MyUpdGallery == object)
    {
        subs = [m_MyUpdGallery.m_RootPanel subviews];
        total = [[m_MyUpdGallery.m_RootPanel subviews] count] - 1;
    }
    
    //left + 
    if (0 == directory)
    {
        //释放图片
        cnt   = (index >= 5) ? (5) : (index);
        start = index - 1;
        for (int i=0; i<cnt; i++)
        {
            ////NSLog(@"释放图片");
            if (m_MyFodGallery == object && start < [m_Favorites count])
            {
                product = [m_Favorites objectAtIndex:start];
                [product ProductCancelLoadIcon];
                item = [subs objectAtIndex:start--];
                item.m_ImageView.image = nil;
            }
            else if (m_MyUpdGallery == object && start < [m_Uploads count])
            {
                product = [m_Uploads objectAtIndex:start];
                [product ProductCancelLoadIcon];
                item = [subs objectAtIndex:start--];
                item.m_ImageView.image = nil;
            }
        }
        //加载图片
        cnt = (index+6 <= total) ? (6) : (total - index);
        start = index;
        (start+cnt <= total) ? (++cnt) : (cnt);
        for (int i=0; i<cnt; i++)
        {
            ////NSLog(@"加载图片");
            if (m_MyFodGallery == object && start < [m_Favorites count])
            {
                product = [m_Favorites objectAtIndex:start];
                item = [subs objectAtIndex:start++];
                if (!item.m_ImageView.image)
                {
                    data = [product GetProductIcon];
                    if (data)
                    {
                        image = [UIImage imageWithData:data];
                    }
                    item.m_ImageView.image = image;
                    image = nil;
                }
            }
            else if (m_MyFodGallery == object && start < [m_Uploads count])
            {
                product = [m_Uploads objectAtIndex:start];
                item = [subs objectAtIndex:start++];
                if (!item.m_ImageView.image)
                {
                    data = [product GetProductIcon];
                    if (data)
                    {
                        image = [UIImage imageWithData:data];
                    }
                    item.m_ImageView.image = image;
                    image = nil;
                }
            }
        }
    }
    //right <-
    else if (1 == directory)
    {
        //加载图片
        cnt = (index >= 5) ? (5) : (index);
        (0 == index) ? (start=index, cnt=1) : (start=index - 1);
        for (int i=0; i<cnt; i++)
        {
            ////NSLog(@"加载图片");
            if (m_MyFodGallery == object && start < [m_Favorites count])
            {
                product = [m_Favorites objectAtIndex:start];
                item = [subs objectAtIndex:start--];
                if (!item.m_ImageView.image)
                {
                    data = [product GetProductIcon];
                    if (data)
                    {
                        image = [UIImage imageWithData:data];
                    }
                    item.m_ImageView.image = image;
                    image = nil;
                }
            }
            else if (m_MyUpdGallery == object && start < [m_Uploads count])
            {
                product = [m_Uploads objectAtIndex:start];
                item = [subs objectAtIndex:start--];
                if (!item.m_ImageView.image)
                {
                    data = [product GetProductIcon];
                    if (data)
                    {
                        image = [UIImage imageWithData:data];
                    }
                    item.m_ImageView.image = image;
                    image = nil;
                }
            }
        }
        //释放图片
        cnt = (index+12 <= total) ? (6) : (total - (index+6));
        start = index+6;
        for (int i=0; i<cnt; i++)
        {
            ////NSLog(@"释放图片");
            if (m_MyFodGallery == object && start < [m_Favorites count])
            {
                product = [m_Favorites objectAtIndex:start];
                [product ProductCancelLoadIcon];
                item = [subs objectAtIndex:start++];
                item.m_ImageView.image = nil;
            }
            else if (m_MyUpdGallery == object && start < [m_Uploads count])
            {
                product = [m_Uploads objectAtIndex:start];
                [product ProductCancelLoadIcon];
                item = [subs objectAtIndex:start++];
                item.m_ImageView.image = nil;
            }
        }
    }
    else {;}
}

@end
